﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.ComponentModel;
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
using LevelEditor.Model.Enum;
using System.Xml.Serialization;

namespace LevelEditor.Model.Entity
{
    [Serializable]
    [XmlInclude(typeof(ActorSprite))]
    [XmlRoot(ElementName = "GameSprite")]
    public class GameSprite : INotifyPropertyChanged
    {
        private String name;
        
        private double x;
        private double y;
        private double width;
        private double height;

        //public int FillInt { get { return (int)Fill; } set { Fill = (SpriteFill)value; } }

        private SpriteFill fill;
        public AssetType AssetType {get;set;}
        public int AssetTypeInt { get { return (int)AssetType; } set { AssetType = (AssetType)value; } }
        public string Category { get; set; }

        public int ZIndex { get; set; }
        public int ID { get; set; }
        public string ElementType { get; set; }

        [XmlIgnore]
        public Uri ImageSource { get; set; }
        public string ImageSourceStr { get { return ImageSource.OriginalString; } set { ImageSource = new Uri(value, UriKind.Relative); } }

        [XmlIgnore]
        public bool IsSelected { get; set; }
        private bool isItemVisible;
        public bool IsItemVisible
        {
            get
            {
                return isItemVisible;
            }
            set
            {
                isItemVisible = value;
                NotifyPropertyChanged("IsItemVisible");
            }
        }
        
        private bool isItemLocked;
        public bool IsItemLocked
        {
            get
            {
                return isItemLocked;
            }
            set
            {
                isItemLocked = value;
                NotifyPropertyChanged("IsItemLocked");
            }
        }
        
        [Category("Information")]
        [DisplayName("Name")]
        public string Name { get { return name; } set { name = value; NotifyPropertyChanged("Name");  } }

        [Category("Appearance")]
        [DisplayName("X")]
        public double X { get { return x; } set { x = value; NotifyPropertyChanged("X"); } }

        [Category("Appearance")]
        [DisplayName("Y")]
        public double Y { get { return y; } set { y = value; NotifyPropertyChanged("Y"); } }

        [Category("Appearance")]
        [DisplayName("Width")]
        public double Width { get { return width; } set { width = value; NotifyPropertyChanged("Width"); } }

        [Category("Appearance")]
        [DisplayName("Height")]
        public double Height { get { return height; } set { height = value; NotifyPropertyChanged("Height"); } }

        [Category("Appearance")]
        [DisplayName("Fill")]
        public SpriteFill Fill { get { return fill; } set { fill = value; NotifyPropertyChanged("Fill"); } }

        //Methods

        public GameSprite Clone() { return (GameSprite)this.MemberwiseClone(); }

        // Implement INotifyPropertyChanged interface.
        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
